package com.example.videoworks.common;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yannis
 * @version 2020/7/23 0:51
 */
@Getter
public enum CommonErrorCode {

    INVALID_SESSION(2006,"会话丢失","登录已失效，请重新登录"),
    USER_NOT_EXIST(2001,"用户不存在","用户不存在"),
    USER_NOT_ADMIN(2002,"用户非管理员","用户非管理员"),
    NEED_SESSION_ID(2003,"未传入sessionId","请传入会话id"),
    LOGIN_HAS_OVERDUE(2004,"登录已过期","登录已过期"),
    SESSION_IS_INVALID(2005,"该session数据库里没有","请在header里key为session处对应有效的sessionId"),
    SELF_INFORMATION_UNWRITTEN(2007,"用户信息不完整，请先完善姓名、学号、院系、专业、年级等信息再进行操作","用户信息不完整，请先完善姓名、学号、院系、专业、年级等信息再进行操作"),
    USER_NOT_SUPERADMIN(2008,"用户不是管理员","用户不是管理员"),
    USER_IS_ADMIN(2009,"用户已经是管理员了","用户已经是管理员了"),
    COMMENT_IS_NOT_ALLOWED(2011,"不能对二级评论进行评论","不能对二级评论进行评论"),
    HAS_LIKED(2012,"该用户已经对该文章点过赞","该用户已经对该文章点过赞"),
    PASSWORD_NOT_RIGHT(2013,"密码不正确","密码不正确，请输入正确的密码"),
    REPETITIVE_DIRECTION(2014,"与已有方向重复","与已有研究方向重复，不可添加"),
    HAVE_NO_SON(2015,"该节点为叶子节点","请输入有子节点的节点id"),
    DOWNLOAD_FILE_FAILED(2016,"下载文件失败","请在浏览器地址栏中输入链接来测试，或者检查网络或系统状况"),
    READ_FILE_ERROR(2017,"读取文件失败","请检查文件格式之后重新上传文件"),
    PAPER_NOT_EXIST(2018,"该论文不存在","只能在目前存在的论文上添加笔记"),
    RESEARCH_DIRECTION_NOT_EXIST(2019,"该研究方向不存在","请输入存在的研究方向id"),
    WRONG_FILE_FORMAT(2019, "文件格式错误", "请上传正确格式的文件"),
    FILENAME_CAN_NOT_BE_NULL(2038, "文件名重复", "请勿上传重名的文件"),
    COMMENT_NOT_EXIST(2020,"该评论不存在","请输入目前系统中存在的评论"),
    FILE_NOT_EXIST(2021, "该文件不存在", "请输入有效的文件名"),
    VERIFICATION_CODE_HAS_EXPIRED(2022, "验证码已过期", "请重新申请发送验证码"),
    HAS_NOT_SENT_EMAIL(2023, "未发送验证码", "请先用此邮箱申请验证码"),
    SEND_EMAIL_FAILED(2024, "发送邮件失败", "请检查邮箱账号"),
    EMAIL_HAS_BEEN_SIGNED_UP(2025, "邮箱已被注册，请使用账号密码登录", "如果忘记密码，请通过邮箱验证找回"),
    VERIFICATION_CODE_WRONG(2026, "邮箱验证码错误", "请输入正确的邮箱验证码"),
    EMAIL_NOT_SIGNED_UP(2027, "该邮箱尚未注册账号", "请输入正确的邮箱或先用此邮箱注册账号"),
    PASSWORD_NOT_QUANTIFIED(2028, "密码强度不够", "请输入符合要求的密码"),
    UPDATE_FAILED(2029, "更新出现竞态条件", "请稍后重试"),
    CAN_NOT_DELETE(2030, "您没有删除该实体的权限", "请选择您能操作的实体进行删除"),
    DO_NOT_SEND_VERIFICATION_CODE_AGAIN(2031, "您上一次验证码尚未失效", "请勿重复发送验证码"),
    DOC_INDEX_FAILED(2032, "索引或文档操作失败", "请等待少许后重试"),
    CAN_NOT_COMMENT(2033, "该用户没有评论的权限", "请联系超管修改权限"),
    CAN_NOT_MODIFY(2034, "不能删除他人评论", "请删除自己评论"),
    PERIOD_NOT_SUPPORTED(2035, "不支持获取这一时间段的数据", "请选择其他时间段"),
    FLOW_LIMITED(2036, "网关服务熔断", "请等待流量缓减后重试"),
    COMENT_NOT_EXIST(2037, "评论不存在", "请重新检查id"),
    UPLOAD_FILE_FAIL(2039, "上传文件失败", "请检查网络状况后稍后重试"),
    CAN_NOT_UPDATE(2040, "已拒绝项目无法修改", "请重新申请"),
    UPLOAD_OVERDUE(2041, "上传超时", "请在规定时间内上传"),
    PROJECT_NOT_EXIST(2042, "项目不存在", "请重新上传项目"),
    ADD_FAIL(2043, "添加失败", "请重新添加"),
    CAN_NOT_HAVE_SAME_NAME(2044, "项目重名", "请重新添加")
    ;


    /**
     * 错误码
     */
    private final Integer errorCode;

    /**
     * 错误原因（给开发看的）
     */
    private final String errorReason;

    /**
     * 错误行动指示（给用户看的）
     */
    private final String errorSuggestion;

    CommonErrorCode(Integer errorCode, String errorReason, String errorSuggestion) {
        this.errorCode = errorCode;
        this.errorReason = errorReason;
        this.errorSuggestion = errorSuggestion;
    }

    @Override
    public String toString() {
        return "CommonErrorCode{" +
                "errorCode=" + errorCode +
                ", errorReason='" + errorReason + '\'' +
                ", errorSuggestion='" + errorSuggestion + '\'' +
                '}';
    }

    //use for json serialization
    public Map<String,Object> toMap(){
        Map<String,Object> map = new HashMap<>();
        map.put("errorCode",errorCode);
        map.put("errorReason",errorReason);
        map.put("errorSuggestion",errorSuggestion);
        return map;
    }


}
